#include "Cmm.h"

PFLT_PORT g_ClientPort;

NTSTATUS FilterConnectNotify(
    IN PFLT_PORT ClientPort,
    IN PVOID ServerPortCookie,
    IN PVOID ConnectionContext,
    IN ULONG SizeOfContext,
    OUT PVOID* ConnectionPortCookie
)
{
    UNREFERENCED_PARAMETER(ClientPort);
    UNREFERENCED_PARAMETER(ServerPortCookie);
    UNREFERENCED_PARAMETER(ConnectionContext);
    UNREFERENCED_PARAMETER(SizeOfContext);
    UNREFERENCED_PARAMETER(ConnectionPortCookie);
    g_ClientPort = ClientPort;
    DBGPRINT("Client connected\r\n");
    return STATUS_SUCCESS;
}

VOID FilterDisconnectNotify(IN PVOID ConnectionCookie)
{
    UNREFERENCED_PARAMETER(ConnectionCookie);

    if (g_ClientPort)
    {
        FltCloseClientPort(g_FilterHandle, &g_ClientPort);
        g_ClientPort = NULL;
        DBGPRINT("Client disconnected\r\n");
    }
}

NTSTATUS FilterMessageNotify(
    IN PVOID PortCookie,
    IN PVOID InputBuffer OPTIONAL,
    IN ULONG InputBufferLength,
    OUT PVOID OutputBuffer OPTIONAL,
    IN ULONG OutputBufferLength,
    OUT PULONG ReturnOutputBufferLength
)
{
    UNREFERENCED_PARAMETER(PortCookie);
    UNREFERENCED_PARAMETER(InputBuffer);
    UNREFERENCED_PARAMETER(InputBufferLength);
    UNREFERENCED_PARAMETER(OutputBuffer);
    UNREFERENCED_PARAMETER(OutputBufferLength);
    UNREFERENCED_PARAMETER(ReturnOutputBufferLength);

    if (InputBufferLength)
    {
        DBGPRINT("Client send message:%s\r\n", (char*)InputBuffer);
        strcpy(OutputBuffer, "Success");
        *ReturnOutputBufferLength = (ULONG)strlen("Success");
    }

    return STATUS_SUCCESS;
}
